package fi.iki.joker.mobilogger.img;

import fi.iki.joker.mobilogger.db.ImageRepoBean;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.widget.TableLayout;

/**
 * This interface defines how image repositories are accessed by other classes.
 * Typically the users include:
 *  - ImagerepositoryConfigEditor, the class responsible of showing the configuration interface to the user.
 *  - The createPost method of classes implementing the BlogInterface, to publish the images contained in the
 *    posting. 
 * 
 * @author JuhaK
 *
 */

public interface ImageRepository {
	
	/**
	 * The implementer of this function needs to ensure that the returned type,
	 * enumeration of type "ImageRepositoryType, is something that
	 * a) is recognized in ImagerepositoryConstants (class)
	 * b) is something that the other methods implementing this interface can act upon.
	 * @return
	 */
	public ImageRepositoryConstants.ImageRepositoryType getRepositoryType();
	
	/**
	 * Implementer needs to make sure that the method returns the token that is used in authentication for the
	 * given image repository. This typically no longer contains the username and password used in the authentication
	 * but is something that the image repository recognizes. 
	 * @param userName
	 * @param passwordr
	 * @return
	 */
	
	public String getAuthId(String userName, String password);
	
	/**
	 * This is the method that the ImageRepoConfig editor calls when user selects the repository type.
	 * It is responsibility of the implementer to make the method such that for give parent activity and context,
	 * it draws the GUI elements necessary to make it possible for the user to input all the credentials and information,
	 * that images can be published to the repository online. The config editor itself implements most typical fields
	 * like password and username. This method is given "free access" to the parent activity, since sometimes creating
	 * a working interface requires that dialogs are opened, threads are started et cetera.
	 * A STRICT contract that implementer needs to obey:
	 * As part of the GUI, place all views inside TableRow objects, which are numbered (setId) starting from starIdFrom
	 * @param parent The parent activity
	 * @param tl The layout object of the parent activity's view.
	 * @param context The context of the application
	 * @param startIdFrom The starting ID number for the TableRow objects that are created by the implementation.
	 * @param populateFromID Unique identifier for the database row where the configuration used by the method is stored.
	 * This is here to maintain proper state for the created editor rows. If user wants to edit a certain configuration,
	 * the ID passed to this method reflects the data row the values for the editor should be loaded from.
	 * @return
	 */
	
	public void drawConfigFields(Activity parent, TableLayout tl, 
			Context context, int startIdFrom, int populateFromID);
	
	/**
	 * The interface config, returned by the implementing method, is the (String) representation of ALL of the 
	 * information that is needed to  
	 * @return
	 */
	
	public String getInterfaceConfig();
	
	public boolean setInterfaceConfig(String config);

	/**
	 * Publishes image imageUri using filename fileName to repository repository. Returns the URL of the published image.
	 * @param parentRef
	 * @param repository
	 * @param imageUri
	 * @param fileName
	 * @return
	 */
	
	public String publishImage(Activity parentRef, ImageRepoBean repository, Uri imageUri, String fileName);
}
